<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Class and object changes</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="migration51.integer-parameters.html">Integer values in function parameters</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="migration51.extensions.html">Extensions</a></div>
 <div class="up"><a href="migration51.html">Migrating from PHP 5.0.x to PHP 5.1.x</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="migration51.oop" class="section">
  <h2 class="title">Class and object changes</h2>
  <ul class="itemizedlist">
   <li class="listitem">
    <p class="para">
     <a href="migration51.oop.html#migration51.oop-functions" class="link"><em>instanceof</em>,
      <em>is_a()</em>, <em>is_subclass_of()</em> and
      <em>catch</em></a>
    </p>
   </li>
   <li class="listitem">
    <p class="para">
     <a href="migration51.oop.html#migration51.oop-methods" class="link">Abstract private methods</a>
    </p>
   </li>
   <li class="listitem">
    <p class="para">
     <a href="migration51.oop.html#migration51.oop-modifiers" class="link">Access modifiers in
      interfaces</a>
    </p>
   </li>
   <li class="listitem">
    <p class="para">
     <a href="migration51.oop.html#migration51.oop-inheritance" class="link">Changes in inheritance
      rules</a>
    </p>
   </li>
   <li class="listitem">
    <p class="para">
     <a href="migration51.oop.html#migration51.oop-constants" class="link">Class constants</a>
    </p>
   </li>
  </ul>

  <div class="section" id="migration51.oop-functions">
   <h2 class="title"><em>instanceof</em>, <em>is_a()</em>,
    <em>is_subclass_of()</em> and <em>catch</em></h2>
   <p class="para">
    In PHP 5.0, <em>is_a()</em> was deprecated and replaced by the
    <em>instanceof</em> operator. There were some issues with the
    initial implementation of <em>instanceof</em>, which relied on
    <em>__autoload()</em> to search for missing classes.
    If the class was not present, <em>instanceof</em> would throw
    a fatal <strong><code>E_ERROR</code></strong> due to the failure of
    <em>__autoload()</em> to discover that class. The same behaviour
    occurred in the <em>catch</em> operator and the
    <em>is_subclass_of()</em> function, for the same reason.
   </p>
   <p class="para">
    None of these functions or operators call <em>__autoload()</em>
    in PHP 5.1.x, and the <em>class_exists()</em> workarounds used
    in code written for PHP 5.0.x, while not problematic in any way, are no
    longer necessary.
   </p>
  </div>

  <div class="section" id="migration51.oop-methods">
   <h2 class="title">Abstract private methods</h2>
   <p class="para">
    Abstract private methods were supported between PHP 5.0.0 and PHP 5.0.4,
    but were then disallowed on the grounds that the behaviours of
    <em>private</em> and <em>abstract</em> are mutually
    exclusive.
   </p>
  </div>

  <div class="section" id="migration51.oop-modifiers">
   <h2 class="title">Access modifiers in interfaces</h2>
   <p class="para">
    Under PHP 5.0, function declarations in interfaces were treated in exactly
    the same way as function declarations in classes. This has not been the
    case since October 2004, at which point only the <em>public</em>
    access modifier was allowed in interface function declarations. Since
    April 2005 - which pre-dates the PHP 5.0b1 release - the
    <em>static</em> modifier has also been allowed. However, the
    <em>protected</em> and <em>private</em> modifiers will
    now throw an <strong><code>E_ERROR</code></strong>, as will
    <em>abstract</em>. Note that this change should not affect your
    existing code, as none of these modifiers makes sense in the context of
    interfaces anyway.
   </p>
  </div>

  <div class="section" id="migration51.oop-inheritance">
   <h2 class="title">Changes in inheritance rules</h2>
   <p class="para">
    Under PHP 5.0, it was possible to have a function declaration in a derived
    class that did not match the declaration of the same function in the base
    class, e.g.
   </p>
   <div class="informalexample">
    <p class="para">
     This code will cause an <strong><code>E_STRICT</code></strong> error to be emitted
     under PHP 5.1.x.
    </p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">Base&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;&amp;</span><span style="color: #0000BB">return_by_ref</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$r&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">$r</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br />class&nbsp;</span><span style="color: #0000BB">Derived&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">Base&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;</span><span style="color: #0000BB">return_by_ref</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </div>

  <div class="section" id="migration51.oop-constants">
   <h2 class="title">Class constants</h2>
   <p class="para">
    Under PHP 5.0.x, the following code was valid:
   </p>
   <div class="informalexample">
    <p class="para">
     Under PHP 5.1.x, redefinition of a class constant will throw a fatal
     <strong><code>E_ERROR</code></strong>.
    </p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">test&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;</span><span style="color: #0000BB">foobar&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'foo'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;</span><span style="color: #0000BB">foobar&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'bar'</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </div>
 </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="migration51.integer-parameters.html">Integer values in function parameters</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="migration51.extensions.html">Extensions</a></div>
 <div class="up"><a href="migration51.html">Migrating from PHP 5.0.x to PHP 5.1.x</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
